package com.diaohw.platform.utility.uml.core;

import cn.hutool.core.io.FileUtil;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.DiagramDescription;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Set;

public class UMLUtils {

    public static Set<String> ignoredM = Set.of("canEqual", "finalize ", "wait0", "clone", "equals", "toString", "hashCode", "getClass", "notify", "notifyAll", "wait", "builder", "createWrapper");

    public static void main(String[] args) throws IOException {

        SourceStringReader sourceStringReader = new SourceStringReader("", StandardCharsets.UTF_8);
        // 获取图片格式
        FileFormat fileFormat = FileFormat.PNG;
        File file = new File("plantuml", "temp.png");

        DiagramDescription image = sourceStringReader.outputImage(FileUtil.getOutputStream(file), new FileFormatOption(fileFormat));
        System.out.println(image.getDescription());
        // 输出图片文件路径
        System.out.println("Image generated at: " + file.getAbsolutePath());
    }


    /**
     * 泛型处理
     */
    public static String processTpeName(String str) {
        String[] split = str.split("\\.");
        if (!str.contains(">")) {
            return split[split.length - 1];
        }
        StringBuilder sb = new StringBuilder();
        for (String s : split) {
            if (s.contains("<")) {
                sb.append(s.split("<")[0]).append("<");
            } else if (s.contains(">")) {
                sb.append(s);
            }
        }
        return sb.toString();
    }


}
